package ${packagePrefix}.controller;

import ${packagePrefix}.domain.entity.${domainObjectName};
import ${packagePrefix}.domain.service.${domainObjectName}Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ${tableComment!""} 控制器
 */
@RestController
@RequestMapping("/api/v1/${domainObjectName?uncap_first}s")
public class ${domainObjectName}Controller {

    private final ${domainObjectName}Service ${domainObjectName?uncap_first}Service;

    @Autowired
    public ${domainObjectName}Controller(${domainObjectName}Service ${domainObjectName?uncap_first}Service) {
        this.${domainObjectName?uncap_first}Service = ${domainObjectName?uncap_first}Service;
    }

    /**
     * 创建${tableComment!""}
     */
    @PostMapping
    public ResponseEntity<${domainObjectName}> create(@RequestBody ${domainObjectName} ${domainObjectName?uncap_first}) {
        return ResponseEntity.ok(${domainObjectName?uncap_first}Service.create(${domainObjectName?uncap_first}));
    }

    /**
     * 根据ID查询${tableComment!""}
     */
    @GetMapping("/{id}")
    public ResponseEntity<${domainObjectName}> findById(@PathVariable Long id) {
        return ResponseEntity.ok(${domainObjectName?uncap_first}Service.findById(id));
    }

    /**
     * 查询所有${tableComment!""}
     */
    @GetMapping
    public ResponseEntity<List<${domainObjectName}>> findAll() {
        return ResponseEntity.ok(${domainObjectName?uncap_first}Service.findAll());
    }

    /**
     * 更新${tableComment!""}
     */
    @PutMapping("/{id}")
    public ResponseEntity<${domainObjectName}> update(@PathVariable Long id, @RequestBody ${domainObjectName} ${domainObjectName?uncap_first}) {
        ${domainObjectName?uncap_first}.setId(id);
        return ResponseEntity.ok(${domainObjectName?uncap_first}Service.update(${domainObjectName?uncap_first}));
    }

    /**
     * 删除${tableComment!""}
     */
    @DeleteMapping("/{id}")
    public ResponseEntity<Void> deleteById(@PathVariable Long id) {
        ${domainObjectName?uncap_first}Service.deleteById(id);
        return ResponseEntity.ok().build();
    }
} 